/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.vaadin;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.TwinColSelect;
import com.vaadin.ui.VerticalLayout;
import java.util.ArrayList;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class TwinColumnSelect extends VerticalLayout implements Property.ValueChangeListener {
    ArrayList<String> selectedOptions = new ArrayList<String>();
    private String selected=null;
    public TwinColumnSelect() {
        setSpacing(true);

        TwinColSelect l = new TwinColSelect();
        l.addItem("No element");
        //l.setVisible(true);
        l.setWidth("600px");

        addComponent(l);
    }
    public String getSelected(){
        return selected;
    }
    public TwinColumnSelect(Elements menuitems) {
        setSpacing(true);

        TwinColSelect l = new TwinColSelect();

        for (Element a : menuitems) {
            l.addItem(a.html().replace("&amp;", "&"));
        }
        l.setRows(8);
        l.setNullSelectionAllowed(true);
        l.setMultiSelect(true);
        l.setImmediate(true);
        l.addListener(this);
//        l.setLeftColumnCaption("Available cities");
//        l.setRightColumnCaption("Selected destinations");
        l.setWidth("650px");
        

        addComponent(l);
    }

    /*
     * Shows a notification when a selection is made.
     */
    @Override
    public void valueChange(ValueChangeEvent event) {
        if (!event.getProperty().toString().equals("[]")) {
            getWindow().showNotification("Selected option : " + event.getProperty());
            selected=event.getProperty().toString();
            
        }
        else
            selected="";
    }
}